package io.hilo.example.app;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.hilo.boot.app.web.GlobalExceptionResolver;
import org.jretty.apibase.Result;
import org.springframework.stereotype.Component;

/**
 * 处理 自定义 全局异常
 * 
 * @author zollty
 * @since 2018-2-23
 */
@Component
public class AppExceptionResolver extends GlobalExceptionResolver {

    @Override
    public Result<?> handleMoreException(HttpServletRequest request, Exception ex) {
        Result<?> r = null;
        
        // 示例如下
        
//        if (ex instanceof AuthorizationException) {
//            r = Result.fail("没有权限，请联系管理员授权");
//            // 记录异常日志
//            logger.error("", ex);
//        }
        
        
        return r;
    }

    @Override
    public Result<?> beforeErrorViewWrite(HttpServletRequest request, HttpServletResponse response,
            Object handler, Exception ex, Result<?> ret) {
        return null;
    }

}
